package com.yc.snack.biz.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yc.snack.biz.IProductInfoBiz;
import com.yc.snack.dao.IProductInfoDao;
import com.yc.snack.dao.impl.ProductInfoDaoImpl;
import com.yc.snack.entity.ProductInfo;
import com.yc.snack.util.StringUtil;

public class ProductInfoBizImpl implements IProductInfoBiz {

	@Override
	public int add(ProductInfo pf) {
		if(StringUtil.checkNull(pf.getGname(),pf.getPrice(),pf.getTno(),pf.getPics())) {
			return -1;
		}
		IProductInfoDao productInfoDao = new ProductInfoDaoImpl();
		return productInfoDao.add(pf);
	}

	@Override
	public List<ProductInfo> finds(int page, int rows) {
		IProductInfoDao productInfoDao = new ProductInfoDaoImpl();
		return productInfoDao.finds(page, rows);
	}

	@Override
	public Map<String, Object> findByFirst(int page, int rows) {
		IProductInfoDao productInfoDao = new ProductInfoDaoImpl();
		List<ProductInfo> list = productInfoDao.finds(page, rows);
		//list.isEmpty() 里面没有数据
		if(list == null || list.isEmpty()) {
			return Collections.emptyMap();
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("total", productInfoDao.total());
		map.put("rows", list);
		return map;
	}

}
